package cn.com.kh;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.elite.EliteBean;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @Title: LogToDB
 * @Description: 将接口交互内容记录到数据库
 * @author: LiJuntao
 * @date 2019-12-13 上午10:05:30
 */

public class LogToDB {
    private static final Log log = LogFactory.getLog(LogToDB.class);

    public static void toDB(final EliteBean eliteBean, final String dataSource, final String Name, final String Type, final String Request, final String Response, final String Consume, final String Remark) {
        try {
            JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());
            String Log_Guid = UUID.randomUUID().toString();
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            final String nowTime = simpleDateFormat.format(date);

            String updateSQL = "Insert Into Ws_Interface_Log (Log_Guid, Name, Time, Type, Request, Response, Consume, Remark) Values (?, ?, ?, ?, ?, ?, ?, ?)";

            jt.update(updateSQL, Log_Guid, Name, nowTime, Type, Request, Response, Consume, Remark);

        } catch (Exception e) {
            log.error("LogToDB Exception:", e);
        }
    }

}